package com.lzc.springcloud.authserver.resources;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.security.Principal;

@Controller
@RequestMapping("identity")
public class UserResource {

    @GetMapping("login.html")
    public String login() {
        return "login";
    }

    @GetMapping("/user")
    @ResponseBody
    public Principal user(Principal user){
        return user;
    }

//    @RequestMapping("login")
//    public String login(HttpServletRequest request, HttpServletResponse response, @RequestParam String userId, @RequestParam String password, Map<String,Object> map) {
//        UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(userId, password);
//        Authentication authentication= authenticationManager.authenticate(token);
//        sessionAuthenticationStrategy.onAuthentication(authentication, request, response);
//
//        SecurityContextHolder.getContext().setAuthentication(authentication);
//        User userDetails = (User) SecurityContextHolder.getContext()
//                .getAuthentication()
//                .getPrincipal();
//        List<GrantedAuthority> authorities = (List<GrantedAuthority>) SecurityContextHolder.getContext()
//                .getAuthentication().getAuthorities();
//        map.put("user", userDetails);
//        map.put("authorities", authorities);
////        map.put("SESSIONID", session.getId());
//        return "index";
//    }
}
